package com.ruifu.proj.service.impl;

import com.ruifu.common.po.PmActiveMain;
import com.ruifu.common.po.PmPtMain;
import com.ruifu.common.po.PmTaskAudit;
import com.ruifu.common.utils.BeanConverter;
import com.ruifu.proj.mapper.PmActiveMainMapper;
import com.ruifu.proj.mapper.PmPtMainMapper;
import com.ruifu.proj.mapper.PmTaskAuditMapper;
import com.ruifu.proj.service.PmActiveMainService;
import com.ruifu.proj.vo.pmActiveMain.PmActiveMainRecordVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 宁义锐
 */
@Service
@Transactional(rollbackFor = Exception.class)
@SuppressWarnings("all")
public class PmActiveMainServiceImpl implements PmActiveMainService {
    @Autowired(required = false)
    private PmActiveMainMapper pmActiveMainMapper;

    @Autowired
    private PmPtMainMapper pmPtMainMapper;

    @Autowired
    private PmTaskAuditMapper pmTaskAuditMapper;

    /**
     * 查询执行记录
     *
     * @param ptId
     * @return
     */
    @Override
    public List<PmActiveMainRecordVO> findById(Long ptId) {
        List<PmActiveMain> pmActiveMains = pmActiveMainMapper.findByPtId(ptId);
        List<PmActiveMainRecordVO> pmActiveMainRecordVOList = BeanConverter.copyList(pmActiveMains, PmActiveMainRecordVO.class);
        //拿到项目任务委托链的最终审核人
        Long assginorId = Long.valueOf(pmPtMainMapper.findById(ptId).getPtAssignors().split(",")[0]);

        for (PmActiveMainRecordVO pmActiveMainRecordVO : pmActiveMainRecordVOList) {
            Map<String, Object> map = new HashMap<>();
            map.put("Pa_pvid", pmActiveMainRecordVO.getPvId());
            map.put("Pa_executer",assginorId);
            PmTaskAudit pmTaskAudit = pmTaskAuditMapper.findByMap(map);
            if (pmTaskAudit!=null){
                pmActiveMainRecordVO.setPaAuditorTime(pmTaskAudit.getPaAuditorTime());
            }
        }
        return pmActiveMainRecordVOList;
    }
}
